package com.ruoyi.task.service.impl;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import com.ruoyi.common.constant.SysConstants;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.task.mapper.SysTaskStepMapper;
import com.ruoyi.task.domain.SysTaskStep;
import com.ruoyi.task.service.ISysTaskStepService;

/**
 * 任务步骤Service业务层处理
 * 
 * @author YJF
 * @date 2022-12-08
 */
@Service
public class SysTaskStepServiceImpl implements ISysTaskStepService 
{
    @Autowired
    private SysTaskStepMapper sysTaskStepMapper;

    /**
     * 查询任务步骤
     * 
     * @param id 任务步骤主键
     * @return 任务步骤
     */
    @Override
    public SysTaskStep selectSysTaskStepById(Long id)
    {

        SysTaskStep taskStepInfo = sysTaskStepMapper.selectSysTaskStepById(id);
        List<Long> sameUuidGroup = Arrays.stream(taskStepInfo.getSameUuid().split(",")).map(s -> Long.parseLong(s.trim())).collect(Collectors.toList());
        List<Long> childUuidGroup = Arrays.stream(taskStepInfo.getChildUuid().split(",")).map(s -> Long.parseLong(s.trim())).collect(Collectors.toList());
        taskStepInfo.setSameUuidGroup(sameUuidGroup);
        taskStepInfo.setChildUuidGroup(childUuidGroup);
        return taskStepInfo;
    }

    /**
     * 查询任务步骤列表
     * 
     * @param sysTaskStep 任务步骤
     * @return 任务步骤
     */
    @Override
    public List<SysTaskStep> selectSysTaskStepList(SysTaskStep sysTaskStep)
    {
        if(StringUtils.isEmpty(sysTaskStep.getDelFlag())){
            sysTaskStep.setDelFlag(SysConstants.CONSTANT_STR0);
        }
        return sysTaskStepMapper.selectSysTaskStepList(sysTaskStep);
    }

    /**
     * 新增任务步骤
     * 
     * @param sysTaskStep 任务步骤
     * @return 结果
     */
    @Override
    public int insertSysTaskStep(SysTaskStep sysTaskStep)
    {
        sysTaskStep.setSameUuid(StringUtils.join(sysTaskStep.getSameUuidGroup(),","));
        sysTaskStep.setChildUuid(StringUtils.join(sysTaskStep.getChildUuidGroup(),","));
        sysTaskStep.setCreateTime(DateUtils.getNowDate());
        sysTaskStep.setUpdateTime(DateUtils.getNowDate());
        return sysTaskStepMapper.insertSysTaskStep(sysTaskStep);
    }
    /**
     * 修改任务步骤
     * 
     * @param sysTaskStep 任务步骤
     * @return 结果
     */
    @Override
    public int updateSysTaskStep(SysTaskStep sysTaskStep)
    {
        sysTaskStep.setSameUuid(StringUtils.join(sysTaskStep.getSameUuidGroup(),","));
        sysTaskStep.setChildUuid(StringUtils.join(sysTaskStep.getChildUuidGroup(),","));
        sysTaskStep.setUpdateTime(DateUtils.getNowDate());
        return sysTaskStepMapper.updateSysTaskStep(sysTaskStep);
    }

    /**
     * 批量删除任务步骤
     * 
     * @param ids 需要删除的任务步骤主键
     * @return 结果
     */
    @Override
    public int deleteSysTaskStepByIds(Long[] ids)
    {
        return sysTaskStepMapper.deleteSysTaskStepByIds(ids);
    }

    /**
     * 删除任务步骤信息
     * 
     * @param id 任务步骤主键
     * @return 结果
     */
    @Override
    public int deleteSysTaskStepById(Long id)
    {
        return sysTaskStepMapper.deleteSysTaskStepById(id);
    }
}
